﻿using Future.Common.Utils;
using Future.IService;
using Microsoft.Extensions.Caching.Distributed;

namespace Future.Service
{
    /// <summary>
    /// 描述：缓存服务
    /// 创建人： yangkai
    /// 创建时间：2022/12/21 17:04:32
    /// </summary>
    public class CacheService : ICacheService
    {
        private readonly IDistributedCache _distributedCache;

        public CacheService(IDistributedCache distributedCache)
        {
            _distributedCache = distributedCache;
        }

        public void Remove(string key)
        {
            _distributedCache.Remove(key);
        }

        public T? GetObject<T>(string key) where T : class
        {
            return _distributedCache.GetObject<T>(key);
        }

        public void SetObject<T>(string key, T value) where T : class
        {
            _distributedCache.SetObject(key, value);
        }

        public void SetObject<T>(string key, T value, int ExpirationTime) where T : class
        {
            _distributedCache.SetObject(key, value, ExpirationTime);
        }
    }
}
